package com.sam.core.dao.jdbc;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;

import com.sam.core.domain.SysConfig;

/**
 * @project mould
 * @author Sam
 * @version
 * @date Nov 11, 2009 3:53:41 PM
 */
@Repository
@SuppressWarnings("unchecked")
public class JdbcDao extends BaseJdbcTemplate {
	public SysConfig loadSysConfig() {
		SysConfig sysConfig = new SysConfig();
		String sql = " SELECT configField, configValue FROM dbo.t_XTSZ_sysconfig ";
		final Map sysConfigMap = new HashMap();
		jdbcTemplate.query(sql, new ResultSetExtractor() {
			public Object extractData(java.sql.ResultSet rs) throws SQLException {
				while (rs.next()) {
					sysConfigMap.put(rs.getString("configField"), rs.getString("configValue"));
				}
				return null;
			}
		});
		try {
			BeanUtils.populate(sysConfig, sysConfigMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysConfig;
	}
}
